package domain.web.controller;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import domain.web.dao.DetailDao;

import process.service.DbBuilderService;
import process.service.MenuParserService;
import process.service.OntoQueryService;

@Controller
public class WebController {

	private final static String VIEW_BASE = "";
	
	@Autowired
	private MenuParserService menuParserService;
	@Autowired
	private DbBuilderService builderService;
	@Autowired
	private OntoQueryService ontoQueryService;
	
	@Autowired
	private DetailDao detailDao;

	/* -------- HOME -------- */
	@RequestMapping(value = "home", method = RequestMethod.GET)
	public String home() {
		return VIEW_BASE + "/home";
	}
	
	@RequestMapping(value = "/template/product", method = RequestMethod.GET)
	public String productDetail() {
		return VIEW_BASE + "/template/product";
	}
	
	@RequestMapping(value = "/template/search", method = RequestMethod.GET)
	public String searchDetail() {
		return VIEW_BASE + "/template/search";
	}
	
	@RequestMapping(value = "/template/list", method = RequestMethod.GET)
	public String list() {
		return VIEW_BASE + "/template/list";
	}
	
	/* -------- ADMIN -------- */
	@RequestMapping(value = "admin", method = RequestMethod.GET)
	public String admin() {
		return VIEW_BASE + "/admin";
	}
	
	@RequestMapping(value = "/admin/adminwelcome", method = RequestMethod.GET)
	public String adminWelcome() {
		return VIEW_BASE + "/admin/adminwelcome";
	}
	
	@RequestMapping(value = "/admin/pageprocess", method = RequestMethod.GET)
	public String pageProcess() {
		return VIEW_BASE + "/admin/pageprocess";
	}
	
	@RequestMapping(value = "/admin/siteprocess", method = RequestMethod.GET)
	public String siteProcess() {
		return VIEW_BASE + "/admin/siteprocess";
	}
	
	@ResponseBody
	@RequestMapping(value = "test", method = RequestMethod.GET)
	public boolean test() throws IOException {
		System.out.println("Start to Parse!!!");
		menuParserService.parse(1,"http://www.nguyenkim.com/", ".wrap-dropdown-multicolumns", ".pagination");
		//menuParserService.parse(2, "http://www.dienmaythienhoa.vn/", ".ddsmoothmenu", ".pagination");
		System.out.println("Parse DONE!!!");
		return true;
	}
	
	@ResponseBody
	@RequestMapping(value = "build", method = RequestMethod.GET)
	public boolean build() {
		System.out.println("Start to build ...");
		builderService.buildManufacturer();
		builderService.buildTopCategory();
		System.out.println("Build done");
		return true;
	}
	
	@ResponseBody
	@RequestMapping(value = "update", method = RequestMethod.GET)
	public boolean update() {
		System.out.println("Start to update ...");
		builderService.updateProduct();
		System.out.println("Update done");
		return true;
	}
	
	@ResponseBody
	@RequestMapping(value = "updateImage", method = RequestMethod.GET)
	public boolean updateImage() {
		System.out.println("Start to update ...");
		detailDao.updateImage(3);
		System.out.println("Update done");
		return true;
	}
}
